package com.codedancer.campus.client.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.service.IAdminService;
import com.codedancer.campus.client.service.vo.admin.AdminVo;
import com.codedancer.campus.mapper.AdminMapper;
import com.codedancer.campus.po.Admin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl implements IAdminService {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 随机获取一名客服管理员
     *
     * @return
     */
    @Override
    public AdminVo randomOne() {
        // 获取全部客服管理员
        List<Admin> admins = adminMapper.listAllCustomerAdmin();
        // 将其顺序打乱
        Collections.shuffle(admins);
        return BeanUtil.copyProperties(admins.get(0), AdminVo.class);
    }
}
